/*
 *  Copyright 2011 Alexey Andreev.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.xthl.core;

import org.nop.core.ControllerServices;
import org.nop.templating.Template;
import org.nop.templating.XmlTreeBuilder;
import org.nop.util.Injected;
import org.xthl.core.api.UserLogic;

/**
 *
 * @author Alexey Andreev
 */
public abstract class AbstractMenuItem implements MenuItemRenderer {
    protected UserLogic userLogic;
    protected ControllerServices services;
    
    @Injected
    public final void setUserLogic(UserLogic userLogic) {
        this.userLogic = userLogic;
    }
    
    @Injected
    public void setServices(ControllerServices services) {
        this.services = services;
    }

    protected final boolean checkPermission(String permission) {
        return userLogic.checkPermission(permission);
    }
    
    protected final Template makeTitle(final String text) {
        return new Template() {
            @Override
            public void generate(XmlTreeBuilder treeBuilder) {
                treeBuilder.addText(text);
            }
        };
    }
    
    protected final <T> T bundle(Class<T> bundleType) {
        return services.getBundle(bundleType);
    }
    
    protected final <T> T route(Class<T> routeType) {
        return services.getRoute(routeType);
    }
}
